package com.pg.agent.engine.client.model.environment;

import com.pg.agent.engine.client.model.sop.Memory;
import com.pg.agent.engine.client.model.sop.ShareMemory;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 上下文环境
 *
 * @author huhuaping
 * @date 2023/11/3 13:40
 */
@Data
public class AIEnvironment implements Serializable {
    private static final long serialVersionUID = 9120606095133429209L;
    /**
     * 共享内存
     */
    private ShareMemory shareMemory;

    /**
     * 系统提示词
     */
    private Map<String, String> summarySystemPrompt;


    /**
     * 环境提示词
     */
    private Map<String, String> environmentPrompt;

    /**
     * 环境类型  cooperative:在不同的状态之间共享信息; competive :不同状态之间没有信息共享
     */
    private String environmentType;

    /**
     * 配置文件
     */
    private Config config;

    /**
     * 当前聊天历史记录索引
     */
    private int currentChatHistoryIdx = 0;


    public List<Memory> getRecentlyMemory() {

        if(this.getShareMemory() == null || this.getShareMemory().getLongMemory()==null){
            return new ArrayList<>();
        }
        List<Memory> memoryList = this.getShareMemory().getLongMemory();
        if (memoryList.size() > this.getCurrentChatHistoryIdx()) {
            memoryList = memoryList.subList(this.getCurrentChatHistoryIdx(), memoryList.size());
        }
        return memoryList;
    }

    public String getQuery() {
        List<Memory> memoryList = this.getShareMemory().getLongMemory();
        if (memoryList !=null && memoryList.size()>0) {
            return memoryList.get(memoryList.size()-1).getContent();
        }
        return "";
    }

}
